package com.shtel.bss.saas.tenant.controller;

import com.github.pagehelper.PageInfo;
import com.shtel.bss.saas.core.data.common.controller.DataController;
import com.shtel.bss.saas.tenant.dto.SysGlobalAuthDTO;
import com.shtel.bss.saas.tenant.dto.UpdateSysTenantAuthDTO;
import com.shtel.bss.saas.tenant.mapstrut.EntityDtoMapper;
import com.shtel.bss.saas.tenant.service.ISysTenantAuthJoinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 租户权限表 controller
 * @author xiezhiwei 2020-02-05 22:03
 */
@RestController
@RequestMapping("/bam/tenants/auth")
public class SysTenantAuthJoinController extends DataController{
    @Autowired
    private ISysTenantAuthJoinService sysTenantAuthJoinService;
    
//    @GetMapping("/{tenantId}")
//    public PageInfo<SysGlobalAuthDTO> querySysGlobalAuthListByTenantId(@PathVariable Long tenantId,
//                                                                       @RequestParam int pageSize, int pageNum){
//        return EntityDtoMapper.INSTANCE.
//                toSysGlobalAuthBoPageInfo(sysTenantAuthJoinService.querySysGlobalAuthListByTenantId(tenantId,pageSize,pageNum));
//    }

    @GetMapping("/{tenantId}")
    public List<SysGlobalAuthDTO> querySysGlobalAuthListByTenantId(@PathVariable Long tenantId){
        return EntityDtoMapper.INSTANCE.
                toSysGlobalAuthBoList(sysTenantAuthJoinService.querySysGlobalAuthListByTenantId(tenantId));
    }

    @PostMapping("/{tenantId}")
    public void updateSysTenantAuth(@PathVariable("tenantId") Long tenantId, @RequestBody UpdateSysTenantAuthDTO updateSysTenantAuthDTO){
        sysTenantAuthJoinService.updateSysTenantAuth(updateSysTenantAuthDTO.getAuthIds(),tenantId,1L);
    }


    @DeleteMapping("/{tenantIds}/{authId}")
    public void deleteSysTenantAuth(@PathVariable("tenantIds") List<Long> tenantIds,@PathVariable("authId") Long authId) {
        sysTenantAuthJoinService.deleteSysTenantAuth(tenantIds,authId);
    }
}